﻿using System.Linq;

namespace YanZhiwei.DotNet3._5.Utilities.Common
{
    /// <summary>
    /// Array帮助类
    /// </summary>
    public static class ArrayHelper
    {
        #region 数组比较
        /// <summary>
        /// 数组比较
        /// </summary>
        /// <typeparam name="T">数组类型</typeparam>
        /// <param name="source">比较数组一</param>
        /// <param name="compare">比较数组二</param>
        /// <returns>相等返回TRUE；不相等返回FALSE</returns>
        public static bool Equals<T>(T[] source, T[] compare)
        {
            return source.SequenceEqual(compare);
        }
        #endregion 
        #region Array添加
        /// <summary>
        /// Array添加
        /// </summary>
        /// <typeparam name="T">泛型</typeparam>
        /// <param name="array">Array</param>
        /// <param name="item">需要添加项</param>
        /// <returns>返回新的Array</returns>
        public static T[] Add<T>(this T[] array, T item)
        {
            array = array.Concat<T>(new T[1] { item }).ToArray();
            return array;
        }
       
        /// <summary>
        ///  Array添加
        /// </summary>
        /// <typeparam name="T">泛型</typeparam>
        /// <param name="sourceArray">Array</param>
        /// <param name="addArray">Array</param>
        /// <returns>返回新的Array</returns>
        public static T[] AddRange<T>(this T[] sourceArray, T[] addArray)
        {
            sourceArray = sourceArray.Concat<T>(addArray).ToArray();
            return sourceArray;
        }
        #endregion
    }
}
